package org.feifei.hrm.controller;


import org.feifei.hrm.doc.CourseDoc;
import org.feifei.hrm.query.CourseDocQuery;
import org.feifei.hrm.repository.CourseDocRepository;
import org.feifei.hrm.service.ICourseDocService;
import org.feifei.hrm.util.AjaxResult;
import org.feifei.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/courseDoc")
public class CourseDocController {
    @Autowired
    private CourseDocRepository repository;

    @Resource
    private ICourseDocService courseDocService;
    //批量添加
    @PostMapping("/add")
    public AjaxResult batchAdd(@RequestBody List<CourseDoc> courseDocs){
        repository.saveAll(courseDocs);
        return AjaxResult.me();
    }

    //批量删除
    @PostMapping("/del")
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        Iterable<CourseDoc> courseDocs = repository.findAllById(ids);
        repository.deleteAll(courseDocs);
        return AjaxResult.me();
    }

    @PostMapping("/queryCourses")
    public PageList<CourseDoc> queryPageData(@RequestBody CourseDocQuery query){
        return  courseDocService.queryPageData(query);
    }
}
